package com.wu.project.admin.component;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.io.File;

/**
 * @author 50816
 */
@Component
public class AppRunner implements ApplicationRunner {

    Logger logger = LoggerFactory.getLogger(AppRunner.class);

    @Value("${app.baseDir}")
    String basePath;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        checkUploadFilePath();
        checkTempPath();
    }

    private void checkUploadFilePath() {
        if (!new File(basePath).exists()) {
            logger.info("文件基本路径不存在,创建文件保存基本路径:{}", basePath);
            new File(basePath).mkdirs();
        } else {
            logger.info("文件保存基本路径已存在");
        }
    }

    private void checkTempPath() {
        if (!new File("/app/admin/temp").exists()) {
            logger.info("文件临时路径不存在,创建文件临时保存路径:{}", basePath);
            new File("/app/admin/temp").mkdirs();
        } else {
            logger.info("文件临时存储路径已存在");
        }
    }
}
